package Classes.LevelManagement.Levels 
{
	import Classes.Objects.Personagens.Inimigos.Voador;
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.b2World;
	import Box2D.Dynamics.*;
	import Box2D.Collision.*;
	import Box2D.Collision.Shapes.*;
	import Box2D.Common.Math.*;
	import Classes.core.World;
	import Classes.LevelManagement.Level_Base;
	import Classes.Main;
	import Classes.Objects.Personagens.Indio;
	import Classes.Objects.Personagens.Inimigo;
	import Classes.Objects.PhysicsObject;
	import Classes.Utils.Input;
	import Classes.Utils.DreamContact;
	import flash.display.Sprite;
	import flash.ui.Keyboard;
	/**
	 * ...
	 * @author Seven Game Studio
	 */
	public class Level3 extends Level_Base
	{
		public var world:World;
		public var wheelArray:Array;
		
		public var scaleFactor: int = 25;
		
		public var heroi:Indio;
		public var chao:PhysicsObject;
		public var inimigo:Inimigo;
		
		private var posicao_final_camera:Number;
		
		private var dreamContact: DreamContact = new DreamContact();
			
		public override function start(listaObjetos:Array):void
		{
			var gravity:b2Vec2 = new b2Vec2(0, 10);
			world = new World(gravity, false, scaleFactor);
			world.SetContactListener(dreamContact);
			world.createLevel(listaObjetos);
			
			heroi = new Indio(world, false, 0, 20, 100, 100, "lobo", 0);
			inimigo = new Voador(world, false, 300, 100, 200, 150, "inimigo", 0);

			posicao_final_camera = 100 ;
			
		}
		
		public override function update():void
		{
			world.Step(1 / 20, 8, 8);
			heroi.update();
			inimigo.update();
			
			
			
			var pos_x:Number;
			var pos_y:Number;
			
			
			pos_x = heroi.body.GetWorldCenter().x * world.scaleFactor;
			pos_y = heroi.body.GetWorldCenter().y * world.scaleFactor;
			
			pos_x = Main.getStage().stageWidth/2 - pos_x;
			pos_y = Main.getStage().stageHeight / 2 - pos_y;
			

			if (Indio.orientacao == false)
			{
				Main.getInstance().MC_tela.x += ((pos_x + 200) - Main.getInstance().MC_tela.x)/20;
				Main.getInstance().MC_tela.y = pos_y;
			}
			else
			{
				Main.getInstance().MC_tela.x += ((pos_x - 200) - Main.getInstance().MC_tela.x)/20;
				Main.getInstance().MC_tela.y = pos_y;
			}

			
			world.ClearForces(); 
		}
		
	}

}